package arraylist;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 2024/5/14 负责完成对菜品的业务实现 上架，浏览信息 17：00
 */
public class FoodOperator {
    //1.定义一个ArrayList集合对象，负责存储对象信息
   
       private ArrayList<Food> foodList = new ArrayList<>();
       
    //2.开发功能,商家菜品功能
    public void  addFood(){
        //3.创建一个菜品对象
        Food f = new Food();
        //4.录入到菜品信息进去
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入菜品的名称");
        String name = sc.next();
        f.setName(name);

        System.out.println("请输入菜品的价格");
        double nextDouble = sc.nextDouble();
        f.setPrice(nextDouble);

        System.out.println("请输入菜品的信息");
        String desc = sc.next();
        f.setDesc(desc);


        //5.把菜品信息存入到集合中
        foodList.add(f);
        System.out.println("上架成功!");
    }

    //6.展示菜品
    public void  showAllFoods(){
        if(foodList.size()==0){
            System.out.println("什么菜品都没有,请上架商品");
            return;
        }
        for (int i = 0; i < foodList.size(); i++) {
            Food food = foodList.get(i);
            System.out.println(food.getName());
            System.out.println(food.getPrice());
            System.out.println(food.getDesc());
        }
    }

    //7.负责展示操作界面
    public void start() {
        while (true) {
            System.out.println("请选择功能");
            System.out.println("1.上架商品");
            System.out.println("2.展示菜品");
            System.out.println("3.退出");
            Scanner sc = new Scanner(System.in);
            System.out.println("请选择您的操作：");
            String command = sc.next();
            switch (command) {
                case "1":
                    addFood();
                    break;
                case "2":
                    showAllFoods();
                    break;
                case "3":
                    System.out.println("下次再来");
                    return;
                default:
                    System.out.println("您输入的命令不存在");
            }

        }
    }
}
